package com.qf.java2201.dao.impl;

import com.qf.java2201.dao.TypeDao;
import com.qf.java2201.pojo.HNews;
import com.qf.java2201.pojo.HType;
import com.qf.java2201.utils.DbUtils1;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class TypeDaoImpl implements TypeDao {

    QueryRunner queryRunner = new QueryRunner(DbUtils1.getDs());

    @Override
    public List<HType> findAllTypes() {
        String sql = "select * from h_type";
        List<HType> query = null;
        try {
            query = queryRunner.query(sql, new BeanListHandler<>(HType.class));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return query;
    }

    @Override
    public List<HNews> findAllNews() {

        String sql = "select * from h_news";
        List<HNews> query = null;
        try {
            query = queryRunner.query(sql, new BeanListHandler<>(HNews.class));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return query;
    }
}
